home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / datetime.zip / SETDATE.ASM < prev    next >
Assembly Source File  |  1988-09-29  |  8KB  |  152 lines

  1. title    SETDATE.ASM
  2. page     ,132
  3. ;*****************************************************************************
  4. ;* Program Name | SETDATE.ASM                                                *
  5. ;*       Author | Gregory B. Besch                                           *
  6. ;*      Created | 9/29/1988 at 22:41                                         *
  7. ;*      Purpose | Set the computer's system date                             *
  8. ;*       Syntax | expL = setdate(expD)                                       *
  9. ;*              | where: expD is the date to set                             *
  10. ;*              |                                                            *
  11. ;*      Example | error = setdate(ctod("09/29/88"))                          *
  12. ;*      Returns | expL  - .f. = no error, date changed successfully.         *
  13. ;*              |         .t. = error encountered, date not changed.         *
  14. ;*              |                                                            *
  15. ;*      Version | Clipper Summer '87                                         *
  16. ;*     Revision | 1.0    Last Revised: 9/29/1988  @ 22:41                    *
  17. ;* ------------------------------------------------------------------------- *
  18. ;*   Copyright (C) 1988 by Gregory B. Besch                                  *
  19. ;*   Released to the public domain 9/30/88.                                  *
  20. ;*****************************************************************************
  21.  
  22. public   SETDATE
  23.  
  24. extrn    __PARINFO:far                             ; Clipper's Parm Info Svc
  25. extrn    __PARDS:far                               ; Clipper's Date 'getter'
  26. extrn    __RETL:far                                ; Clipper's Logical return
  27.  
  28. ; =======[ EQUATES ]======================================================== ;
  29.          UNDEFINED      EQU   0
  30.          CHARACTER      EQU   1
  31.          NUMERIC        EQU   2
  32.          LOGICAL        EQU   4
  33.          DATE           EQU   8
  34.          BY_REFERENCE   EQU   32
  35.          MEMO           EQU   65
  36.  
  37. ; =======[ DATA ]=========================================================== ;
  38. DGROUP   GROUP    DATASG                           ; Clipper's Data Segment
  39.          DATASG   SEGMENT   PUBLIC    '_DATA'
  40.  
  41.          ; ----------------------------------------------------------------- ;
  42.          ; Storage                                                           ;
  43.          ; ----------------------------------------------------------------- ;
  44.          SYSDATE        db    DATE dup(0)
  45.          SYSYEAR        dw    0
  46.          SYSMON         db    0
  47.          SYSDAY         db    0
  48.  
  49. DATASG   ENDS
  50.  
  51.  
  52. ; =======[ CODE ]=========================================================== ;
  53. ;
  54. _PROG    SEGMENT  BYTE  'CODE'
  55.          ASSUME   CS:_PROG,DS:DGROUP
  56.  
  57. SETDATE  PROC     FAR
  58.          ; ----------------------------------------------------------------- ;
  59.          ; Save registers                                                    ;
  60.          ; ----------------------------------------------------------------- ;
  61.          push     bp
  62.          mov      bp,sp                   ; Establish addressability to stack
  63.          push     ds
  64.          push     es
  65.          push     si
  66.          push     di
  67.  
  68.          ; ----------------------------------------------------------------- ;
  69.          ; Get parameters                                                    ;
  70.          ; ----------------------------------------------------------------- ;
  71. ;---------------------
  72. ;  Debugger breakpoint
  73. ;         db       0CCh
  74. ;---------------------
  75. Parm1:   mov      ax,1                    ; parm number 1:  Date
  76.          push     ax                      ; pass to ParInfo on stack
  77.          call     __PARINFO               ; ask ParInfo what type
  78.          add      sp,2                    ; restore stack
  79.          cmp      ax,DATE                 ; is 1st parm date?
  80.          je       Get1st                  ; if so, press on
  81.          mov      ax,1                    ; if not, set ax = .t.
  82.          jmp      Exit                    ;  and exit
  83. Get1st:  mov      ax,1                    ; 1st parm:  Date
  84.          push     ax                      ; pass to ParInfo on stack
  85.          call     __PARDS                 ; call Clipper's character getter
  86.          add      sp,2                    ; restore stack
  87.  
  88. xsetup:  push     ds                      ; save data seg
  89.          mov      ds,dx                   ; transfer string segment ptr to es
  90.          mov      si,ax                   ; transfer string offset ptr to di
  91.          pop      es                      ; load data segment into es
  92.          lea      di,SYSDATE              ; load variable offset into di
  93.          mov      cx,8                    ; cx = 8 byte max string size
  94.          cld
  95. xfer:    rep      movsb                   ; move system date
  96.  
  97. convert: push     es                      ; transfer data segment back to ds
  98.          pop      ds                      ;  via stack
  99.          lea      si,SYSDATE              ; point es:si to SYSDATE
  100.          mov      cx,4                    ; count = 4 bytes for year
  101.          mov      dx,0                    ; starting value of zero
  102.          call     DEC2BIN                 ; convert year to binary
  103.          mov      [SYSYEAR],dx            ; save converted year
  104.          mov      cx,2                    ; count = 2 bytes for month
  105.          mov      dx,0                    ; starting value of zero
  106.          call     DEC2BIN                 ; convert month to binary
  107.          mov      [SYSMON],dl             ; save converted month
  108.          mov      cx,2                    ; count = 2 bytes for day
  109.          mov      dx,0                    ; starting value of zero
  110.          call     DEC2BIN                 ; convert day to binary
  111.          mov      [SYSDAY],dl             ; save converted day
  112.          
  113. dateset: mov      ah,2Bh                  ; DOS Set Date service
  114.          mov      dh,[SYSMON]             ; system month
  115.          mov      dl,[SYSDAY]             ; system day
  116.          mov      cx,[SYSYEAR]            ; system year
  117.          int      21h                     ; call DOS to set date
  118.          mov      ah,0                    ; zero ah for return
  119.  
  120. exit:    pop      di                      ; restore registers
  121.          pop      si
  122.          pop      es
  123.          pop      ds
  124.          pop      bp
  125.  
  126.          push     ax                      ; push return code on stack
  127.          call     __RETL                  ; and return it to clipper
  128.          add      sp,2                    ; restore stack
  129.          ret                              ; bye bye
  130.  
  131. DEC2BIN  PROC     NEAR
  132. GetDigit:push     cx
  133.          lodsb                            ; Get a digit
  134.          sub      al,30h                  ; convert to binary
  135.          cbw                              ; convert to word
  136.          push     ax                      ; save it temporarily
  137.          mov      ax,dx                   ; get current value
  138.          mov      cx,10                   ; multiplier
  139.          mul      cx                      ; adjust for place value
  140.          mov      dx,ax                   ; move it back to dx
  141.          pop      ax                      ; retrieve current digit
  142.          add      dx,ax                   ; add it to cumulative value
  143.          pop      cx                      ; restore digit count
  144.          loop     GetDigit                ; and get next digit
  145.          ret
  146. DEC2BIN  ENDP
  147.  
  148. SETDATE  ENDP
  149.  
  150. _PROG    ENDS                             ; End of segment
  151.          END
  152.